package com.letv.whatslive.model.convert;

import com.letv.whatslive.model.WeidianUserItems;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by wangjian7 on 2016/9/20.
 */
public class WeidianUserItemsConvert {


    public static DBObject castWeidianUserItemsToDBObject(WeidianUserItems weidianUserItems) {
        DBObject dbo = new BasicDBObject();
        if (weidianUserItems.getId() != null) {
            dbo.put("_id", weidianUserItems.getId());
        }
        dbo.put("userId", ObjUtils.toLong(weidianUserItems.getUserId()));
        dbo.put("itemid", ObjUtils.toString(weidianUserItems.getItemid()));
        dbo.put("openid", ObjUtils.toString(weidianUserItems.getOpenid()));
        dbo.put("recomend", ObjUtils.toInteger(weidianUserItems.getRecomend()));
        dbo.put("priority", ObjUtils.toLong(weidianUserItems.getPriority(), 0L));

        return dbo;
    }

    public static WeidianUserItems castDBObjectToWeidianUserItems(DBObject dbObject) {
        WeidianUserItems weidianUserItems = new WeidianUserItems();
        if (dbObject != null) {
            weidianUserItems.setId(ObjUtils.toLong(dbObject.get("_id")));
            weidianUserItems.setUserId(ObjUtils.toLong(dbObject.get("userId")));
            weidianUserItems.setItemid(ObjUtils.toString(dbObject.get("itemid")));
            weidianUserItems.setOpenid(ObjUtils.toString(dbObject.get("openid")));
            weidianUserItems.setRecomend(ObjUtils.toInteger(dbObject.get("recomend")));
            weidianUserItems.setPriority(ObjUtils.toLong(dbObject.get("priority")));
        }
        return weidianUserItems;
    }
}
